// @description Adds an option to download and convert YouTube videos.
// @namespace http://googlesystem.blogspot.com
// @include http://*.youtube.com/watch?*
// @include http://youtube.com/watch?*
// @version 0.3
// ==/UserScript==
(function () {
if (document.getElementById('convert-youtube-video')) return;
var video_id = null;
var video_hash = null;
var video_player = document.getElementById('movie_player');
if (video_player) {
var flash_variables = video_player.attributes.getNamedItem('flashvars');
if (flash_variables) {
var flash_values = flash_variables.value;
if (flash_values) {
var video_id_match = flash_values.match(/video_id=([^(\&|$)]*)/);
if (video_id_match!=null) video_id = video_id_match[1];
var video_hash_match = flash_values.match(/&t=([^(\&|$)]*)/);
if (video_hash_match!=null) video_hash = video_hash_match[1];
var title=document.title.replace(/'/g,"");
var title=title.replace(/"/g,"");
}
}
}
if (video_id==null) {
var args = unsafeWindow.swfArgs;
if (args) {
video_id = args['video_id'];
video_hash = args['t'];
}
}
if (video_id==null) return;
var youtube2mp3path ='http://www.video2mp3.net/?v='+encodeURIComponent(video_id);
var youtube2mp3path_hq ='http://www.video2mp3.net/?v='+encodeURIComponent(video_id)+"&hq=1";
var div_embed = document.getElementById('watch-embed-div');
if (div_embed) {
div_embed.innerHTML = div_embed.innerHTML + '<br /> <span id=\'convert-youtube-video\'> <a href=\''+youtube2mp3path+'\' title=\'Convert this video into MP3 and download it (Standard Quality)\' target=\'_blank\'>Video2mp3: <b>Convert & Download as MP3</b></a></span>';
div_embed.innerHTML = div_embed.innerHTML + '<br /> <span id=\'convert-youtube-video-hq\'> <a href=\''+youtube2mp3path_hq+'\' title=\'Convert this video into MP3 and download it (High Quality, not available for all videos and longer conversion time!)\' target=\'_blank\'>Video2mp3: <b>Convert & Download as MP3 (HQ)</b></a></span>';